import { _decorator, Component, Node, resources } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('ResourcesManager')
export class ResourcesManager extends Component{

    private static _instance: ResourcesManager = null;

    public static get instance(): ResourcesManager {
        return this._instance;
    }
    

    protected onLoad(): void {
        ResourcesManager._instance = this;
    }

    //加载json
    loadJson(path:string): Promise<any> {
        return new Promise((resolve, reject) => {
            resources.load(path, (err, data) => {
                if (err) {
                    console.error("防御塔json加载失败", err);
                    reject(err);
                } else {
                    resolve(data);
                }
            });
        });
    }

    //加载json
    public static loadGameData(path: string): Promise<any> {
        return new Promise((resolve, reject) => {
            resources.load(path, (err, data) => {
                if (err) {
                    console.error("防御塔json加载失败", err);
                    reject(err);
                } else {
                    resolve(data);
                }
            });
        });
    }
}


